<?php

namespace Yj\Generator\Core\Processor;

use Hyperf\Di\Annotation\Inject;

use Yj\Generator\Core\Config;
use Yj\Generator\Core\Helper\Helper;
use Yj\Generator\Core\Model\ClassNameModel;
use Yj\Generator\Core\Model\DocBlockModel;
use Yj\Generator\Core\Model\EloquentModel;
use Yj\Generator\Core\Model\PropertyModel;
use Yj\Generator\Core\Model\UseClassModel;

/**
 * @Notes: []
 * @User: zwc
 * @Date: 2022/2/28 20:08
 */
class TableNameProcessor
{

    /**
     * @Inject()
     * @var Helper
     */
    protected $helper;

    public function process(EloquentModel $eloquentModel, Config $config)
    {
        $className = $config->get('class_name');
        $baseClassName = $config->get('base_class_name');
        $tableName = $config->get('table_name');

        $eloquentModel->addUses(new UseClassModel(ltrim($baseClassName, '\\')));
        $eloquentModel->setName(new ClassNameModel($className, $this->helper->getShortClassName($baseClassName)));
        $eloquentModel->setTableName($tableName ?: $this->helper->getDefaultTableName($className));

        $property = new PropertyModel('table', 'protected', $eloquentModel->getTableName());
        $property->setDocBlock(new DocBlockModel('The table associated with the model.', '', '@var string'));
        $eloquentModel->addProperty($property);

//        $property = new PropertyModel('table', 'protected', $model->getTableName());
    }

}